// components/goodList/index.js
import {
    postCartAdd
} from '../../api/store.js';
import {
    getCartCounts
} from '../../api/order.js';
var app = getApp();
Component({
    properties: {
        status: {
            type: String,
            value: 0,
        },
        bastList: {
            type: Object,
            value: [],
        }
    },
    data: {

    },
    methods: {
        shopping: function (e) {
            if (app.globalData.isLog === false) {
                this.triggerEvent('purchase');
            }else{
            postCartAdd({
                productId: e.currentTarget.dataset.id,
                cartNum: 1,
                uniqueId: '',
                'new': 0,
                'quick': 1,
            }).then(res => {
                app.Tips({
                    title: '添加购物车成功',
                })
                this.getCartCount();
            }).catch(err => {
                return app.Tips({ title: err });
            })
            }
        },
        getCartCount: function () {
            var that = this;
            getCartCounts().then(res => {
                app.globalData.cart_count = res.data.count.toString();
                wx.setTabBarBadge({
                    index: 3,
                    text: app.globalData.cart_count
                })
            });
        }
    }
})